package cn.weekimwee.map3d

import android.graphics.Color
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import cn.weekimwee.map3d.utilk.Main4Activity
import com.amap.api.maps.AMap
import com.amap.api.maps.CameraUpdateFactory
import com.amap.api.maps.model.LatLngBounds
import com.amap.api.maps.model.MyLocationStyle
import com.amap.api.services.core.LatLonPoint
import com.amap.api.services.route.*
import kotlinx.android.synthetic.main.activity_main.*
import org.jetbrains.anko.startActivity

class MainActivity : AppCompatActivity() {
    private lateinit var aMap:AMap
    private lateinit var myLocationStyle:MyLocationStyle
    private var startPoint = LatLonPoint(29.920906,121.535167)
    private var endPoint = LatLonPoint(29.857785,121.580055)
    private lateinit var routeSearch : RouteSearch
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        map.onCreate(savedInstanceState)
        aMap = map.map
        myLocationStyle = MyLocationStyle()
        myLocationStyle.interval(2000)
        myLocationStyle.strokeWidth(0f)
        myLocationStyle.radiusFillColor(Color.TRANSPARENT)
        myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE)
        aMap.myLocationStyle = myLocationStyle
        aMap.isMyLocationEnabled = true
        aMap.moveCamera(CameraUpdateFactory.zoomTo(14f))
        routeSearch = RouteSearch(this)
        routeSearch.setRouteSearchListener(object: RouteSearch.OnRouteSearchListener{
            override fun onDriveRouteSearched(p0: DriveRouteResult?, p1: Int) {
                TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
            }

            override fun onBusRouteSearched(p0: BusRouteResult?, p1: Int) {
                TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
            }

            override fun onRideRouteSearched(p0: RideRouteResult?, p1: Int) {
                TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
            }

            override fun onWalkRouteSearched(p0: WalkRouteResult?, p1: Int) {
                TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
            }

        })
//        var fromAndTo = RouteSearch.FromAndTo(startPoint,endPoint)
//        var driveRouteQuery = RouteSearch.DriveRouteQuery(fromAndTo,RouteSearch.DrivingDefault,null,null,"")
//        routeSearch.calculateDriveRoute(driveRouteQuery)
        text.setOnClickListener { startActivity<TestActivity>() }
        text1.setOnClickListener { startActivity<NaviActivity>()}
    }

    override fun onResume() {
        super.onResume()
        map.onResume()
    }

    override fun onPause() {
        super.onPause()
        map.onPause()
    }

    override fun onSaveInstanceState(outState: Bundle?) {
        super.onSaveInstanceState(outState)
        map.onSaveInstanceState(outState)
    }

    override fun onDestroy() {
        super.onDestroy()
        map.onDestroy()
    }


}
